﻿Imports MySql.Data.MySqlClient
Public Class DATelasEvento

    Public Function Salvar(ByVal strIdEvento As String, ByVal objBETelasEvento As BE.BETelaEvento) As String
        Dim objBD As New BancoDeDados
        Dim strIdTela As String = objBETelasEvento.IdTela
        Try
            If strIdTela = "" Then
                strIdTela = objBD.ExecutaEscalar("INSERT INTO ext_tela_evento (id_evento, conteudo, nome, ordem, mostra) VALUES ('" & strIdEvento & "', '" & objBETelasEvento.Conteudo & "', '" & objBETelasEvento.Nome & "', " & objBETelasEvento.Ordem & ", " & IIf(objBETelasEvento.Mostra = True, "1", "0)"))
            Else
                objBD.ExecutaNonQuery("UPDATE ext_tela_evento SET id_evento = '" & strIdEvento & "', conteudo = '" & objBETelasEvento.Conteudo & "', nome = '" & objBETelasEvento.Nome & "', ordem = '" & objBETelasEvento.Ordem & "', mostra = '" & IIf(objBETelasEvento.Mostra = True, "1", "0") & "' WHERE id_tela = '" & objBETelasEvento.IdTela & "'")
            End If
            Return strIdTela
        Catch ex As ApplicationException

            Throw New ApplicationException("extranet.DA.DATelasEvento.Salvar(): " & ex.Message)

        End Try
        Return strIdTela
    End Function

    Public Sub Deletar(ByVal strIdTela As String)
        Dim objBD As New BancoDeDados
        Try
            objBD.ExecutaNonQuery("DELETE FROM ext_tela_evento WHERE id_tela = '" & strIdTela & "'")
        Catch ex As ApplicationException
            Throw New ApplicationException("extranet.DA.DATelaEvento.Deletar(): " & ex.Message)
        End Try
    End Sub
    Public Function Listar(ByVal strIdEvento As String) As List(Of BE.BETelaEvento)
        Dim objBD As New BancoDeDados
        Dim objDS As DataSet
        Dim lstBETelaEvento As New List(Of BE.BETelaEvento)
        objDS = objBD.ExecutaQuery("SELECT * FROM ext_tela_evento WHERE id_evento = '" & strIdEvento & "'")
        For Each objDR As DataRow In objDS.Tables(0).Rows
            Dim objBETelaEvento As New BE.BETelaEvento()
            objBETelaEvento.IdEvento = objDR("id_evento").ToString()
            objBETelaEvento.IdTela = objDR("id_tela").ToString()
            objBETelaEvento.Conteudo = objDR("conteudo").ToString()
            objBETelaEvento.Nome = objDR("nome").ToString()
            objBETelaEvento.Ordem = Convert.ToInt32(objDR("ordem").ToString())
            objBETelaEvento.Mostra = objDR("mostra")
            lstBETelaEvento.Add(objBETelaEvento)
        Next
        Return lstBETelaEvento
    End Function
    Public Function Selecionar(ByVal strIdTelaEvento As String) As BE.BETelaEvento
        Dim objBD As New BancoDeDados
        Dim objDS As DataSet
        Dim objBETelaEvento As New BE.BETelaEvento()
        objDS = objBD.ExecutaQuery("SELECT * FROM ext_tela_evento WHERE id_tela = '" & strIdTelaEvento & "'")
        If objDS.Tables(0).Rows.Count <> 0 Then
            objBETelaEvento.IdEvento = objDS.Tables(0).Rows(0)("id_evento").ToString()
            objBETelaEvento.IdTela = objDS.Tables(0).Rows(0)("id_tela").ToString()
            objBETelaEvento.Conteudo = objDS.Tables(0).Rows(0)("conteudo").ToString()
            objBETelaEvento.Nome = objDS.Tables(0).Rows(0)("nome").ToString()
            objBETelaEvento.Ordem = Convert.ToInt32(objDS.Tables(0).Rows(0)("ordem").ToString())
            objBETelaEvento.Mostra = objDS.Tables(0).Rows(0)("mostra")
        End If
        Return objBETelaEvento
    End Function
End Class
